layui.use(['element', 'form', 'layedit','upload'], function () {
    var form = layui.form;
    var $ = layui.jquery,upload = layui.upload;

    //首页logo
    var uploadInst = upload.render({
        elem: '#logo_home'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#config_logo_home_url').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
            console.log(res.data.src)
            $('#config_logo_home').val(res.data.src);
        }
        ,error: function(){
            //演示失败状态，并实现重传
            return layer.msg('上传失败');
        }
    });

    var uploadInst = upload.render({
        elem: '#logo_btn'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#config_logo_btn_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#hom_pic').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    var uploadInst = upload.render({
        elem: '#wechats_btn'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#wechat_code_btn_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#wechat_code').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //about banner1
    var uploadInst = upload.render({
        elem: '#ABOUT_BANNER1_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#ABOUT_BANNER1_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#ABOUT_BANNER1').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //about banner2
    var uploadInst = upload.render({
        elem: '#ABOUT_BANNER2_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#ABOUT_BANNER2_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#ABOUT_BANNER2').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //about 右侧
    var uploadInst = upload.render({
        elem: '#ABOUT_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#ABOUT_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#ABOUT_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //about title
    var uploadInst = upload.render({
        elem: '#ABOUT_RIGHT_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#ABOUT_RIGHT_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#ABOUT_RIGHT').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //magazine title
    var uploadInst = upload.render({
        elem: '#MAGAZINE_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#MAGAZINE_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#MAGAZINE_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner title
    var uploadInst = upload.render({
        elem: '#PARTNER_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#PARTNER_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#PARTNER_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner person
    var uploadInst = upload.render({
        elem: '#PARTNER_PERSON_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#PARTNER_PERSON_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#PARTNER_PERSON').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner brand
    var uploadInst = upload.render({
        elem: '#PARTNER_BRAND_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#PARTNER_BRAND_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#PARTNER_BRAND').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item1
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME1_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME1_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME1').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item2
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME2_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME2_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME2').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item3
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME3_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME3_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME3').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item4
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME4_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME4_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME4').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item5
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME5_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME5_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME5').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item6
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME6_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME6_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME6').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item7
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME7_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME7_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME7').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner item8
    var uploadInst = upload.render({
        elem: '#BENEFITS_ITME8_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_ITME8_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_ITME8').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner title
    var uploadInst = upload.render({
        elem: '#BENEFITS_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //partner right
    var uploadInst = upload.render({
        elem: '#BENEFITS_RIGHT_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_RIGHT_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_RIGHT').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //news title
    var uploadInst = upload.render({
        elem: '#NEWS_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#NEWS_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#NEWS_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //news rught1
    var uploadInst = upload.render({
        elem: '#NEWS_RIGHT1_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#NEWS_RIGHT1_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#NEWS_RIGHT1').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //news rught2
    var uploadInst = upload.render({
        elem: '#NEWS_RIGHT2_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#NEWS_RIGHT2_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#NEWS_RIGHT2').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //news rught3
    var uploadInst = upload.render({
        elem: '#NEWS_RIGHT3_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#NEWS_RIGHT3_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#NEWS_RIGHT3').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //user title
    var uploadInst = upload.render({
        elem: '#USER_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#USER_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#USER_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //user setp_title
    var uploadInst = upload.render({
        elem: '#USER_SETP_TITLE_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#USER_SETP_TITLE_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#USER_SETP_TITLE').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //user setp1
    var uploadInst = upload.render({
        elem: '#USER_SETP1_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#USER_SETP1_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#USER_SETP1').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //user setp2
    var uploadInst = upload.render({
        elem: '#USER_SETP2_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#USER_SETP2_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#USER_SETP2').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //user setp3
    var uploadInst = upload.render({
        elem: '#USER_SETP3_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#USER_SETP3_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#USER_SETP3').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //user setp3
    var uploadInst = upload.render({
        elem: '#BENEFITS_H2_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#BENEFITS_H2_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#BENEFITS_H2').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    var uploadInst = upload.render({
        elem: '#USER_LIYU_bt'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#USER_LIYU_show').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#USER_LIYU').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });
})